//引入Vue核心库
import Vue from "vue";
//引入Vuex
import Vuex from "vuex";
//应用Vuex插件
Vue.use(Vuex);

//准备actions对象——响应组件中用户的动作
const actions = {};
//准备mutations对象——修改state中的数据
const mutations = {
  // login(state, value) {
  //     state.loginUrlAvatar = value;
  //     state.isLogin = true;
  // },
  // showLoading(state, val) {
  //     let loadingInstance = Loading.service(state.options);
  //     val ? Loading.service(state.options) : loadingInstance.close() //这里判断调用方法时候的参数值，打开服务的时候传true，关闭服务的时候传false
  // },

  logout(state, value) {
    state.isLogin = false;
    state.userInfo.email = "";
    state.userInfo.userArticleCount = 0;
    state.userInfo.uid = "";
    state.userInfo.nickname = "";
    state.userInfo.loginUrlAvatar = "";
  },
  setUserMsg(state, value) {
    state.userInfo = {
      loginUrlAvatar: value.loginUrlAvatar,
      nickname: value.nickname,
      remember: value.rememberMe,
      username: value.username,
      email: value.email,
      userArticleCount: value.userArticleCount,
      uid: value.userId,
    };
    state.isLogin = true;
  },
  setUserPassword(state, value) {
    state.userInfo.password = value;
  },
  setTagCount(state, value) {
    state.tagCount = value;
  },
  setArticleCount(state, value) {
    state.articleCount = value;
  },
  setClassifyCount(state, value) {
    state.classifyCount = value;
  },
};
//准备state对象——保存具体的数据
const state = {
  userInfo: {},
  isLogin: false,
  classifyCount: 0,
  tagCount: 0,
  articleCount: 0,
  // options: {
  //     fullscreen: true,//是否全屏
  //     lock: true,
  //     text: '',//自定义文字
  //     spinner: 'null',//自定义图标，不填为默认的，填入不存在的找不到图标就不显示
  //     background: 'rgba(0, 0, 0, .1)',//自定义背景色
  //     customClass: "osloading",//自定义类名
  // },
};

const getters = {};
//创建并暴露store
export default new Vuex.Store({
  actions,
  mutations,
  state,
  getters,
});
//   logout(state, value) {
//     userInfo = {
//     };
//     blogInfo = {};
// },
// setUserMsg(state, value) {
//     state.loginUrlAvatar = value.loginUrlAvatar;
//     state.nickname = value.nickname;
//     state.username = value.username;
//     state.email = value.email;
//     state.userArticleCount = value.userArticleCount;
//     state.uid = value.userId
//     state.isLogin = true;
// },
// }
// //准备state对象——保存具体的数据
// const state = {
// userInfo: {
//     loginUrlAvatar: "",
//     nickname: "",
//     username: "",
//     email: "",
//     uid: "",
//     userArticleCount: "",
//     isLogin: false,
// },
// blogInfo: {
//     classifyCount: "",
//     tagCount: "",
//     articleCount: "",
// }
// }
